import 'package:baselib/util/common_utils.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_app/controller/MineControl.dart';
import 'package:flutter_app/model/trade_bean.dart';
import 'package:get/get.dart';
class TradeRecordPage extends StatefulWidget{
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return new TradeRecordPageState();
  }
}

class TradeRecordPageState extends State<TradeRecordPage>{
  final MineController control = Get.put(MineController());

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    control.getTradeInfos(context);
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Obx(()=>control.records.value.length==0?emptyView():
    PaginatedDataTable(
        rowsPerPage:control.pageSize ,
        columns: [
          DataColumn(label:Text("交易流水号",style: TextStyle(color: Color(0xff2E2F33)),),),
          DataColumn(label:Text("交易时间",style: TextStyle(color: Color(0xff2E2F33)),),),
          DataColumn(label:Text("账号",style: TextStyle(color: Color(0xff2E2F33)),),),
          DataColumn(label:Text("姓名",style: TextStyle(color: Color(0xff2E2F33)),),),
          DataColumn(label:Text("交易类型",style: TextStyle(color: Color(0xff2E2F33)),),),
          DataColumn(label:Text("金额",style: TextStyle(color: Color(0xff2E2F33)),),),
        ],
        onPageChanged:(e){
          if(e>((control.page.value-1)*control.pageSize-1)) {
            control.getTradeInfos(context);
          }
        },
        source: MyDataTableSource(control.tradeBean.value,control.records.value)
    ));
  }
}

Widget emptyView(){
  return Center(
    child: Column(
      children: [
        Image.asset(CommonUtils.getImgPath("personal-center-empty.png")),
        Text("这里空空如也",style: TextStyle(color: Color(0xff2E2F33)),)
      ],
    ),
  );
}

class MyDataTableSource extends DataTableSource {
  final MineController control = Get.put(MineController());
  final TradeBean data;
  final List<Items> _items;
  MyDataTableSource(this.data,this._items);

  @override
  DataRow getRow(int index) {
    // TODO: implement getRow
    if (index >= _items.length) {
      return null;
    }
    return DataRow.byIndex(
      index: index,
      cells: [
        DataCell(Text('${_items[index].transactionNo}',style: TextStyle(color: Color(0xff5C5E66)),)),
        DataCell(Text('${_items[index].createTime}',style: TextStyle(color: Color(0xff5C5E66)),)),
        DataCell(Text('${_items[index].username}',style: TextStyle(color: Color(0xff5C5E66)),)),
        DataCell(Text(CommonUtils.isNull(_items[index].name),style: TextStyle(color: Color(0xff5C5E66)),)),
        DataCell(Text(_items[index].typeText,style: TextStyle(color: Color(0xff5C5E66)),)),
        DataCell(Text('${_items[index].amount}',style: TextStyle(color: Color(0xff5C5E66)),)),
      ],
    );
  }

  @override
  // TODO: implement isRowCountApproximate
  bool get isRowCountApproximate => false;

  @override
  // TODO: implement rowCount
  int get rowCount => int.parse(data.total);

  @override
  // TODO: implement selectedRowCount
  int get selectedRowCount => 0;

}

